import tensorflow as tf


def pearson_correlation(x, y):
    x = x - tf.reduce_mean(x, 1, keepdims=True)
    y = y - tf.reduce_mean(y, 1, keepdims=True)
    x = tf.nn.l2_normalize(x, 1)
    y = tf.nn.l2_normalize(y, 1)
    return tf.reduce_sum(x * y, 1, keepdims=True)
